﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;

using ThingPower.WeChat.MP.AdvancedAPIs;

namespace WeChatDemo
{
    /// <summary>
    /// getOpenID 的摘要说明
    /// </summary>
    public class getOpenID : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //string url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx71dae64ee25e0920&redirect_uri=http://www.shtraining.net/wx/openid.html&response_type=code&scope=snsapi_base&state=1#wechat_redirect";

            string strCode = context.Request["code"];
            //string strAppId = "wx71dae64ee25e0920";
            //string strAppSecret = "4ab5fe683697520c7edb5cd233497a9c";
            string strAppId = WebConfigurationManager.AppSettings["appID"];
            string strAppSecret = WebConfigurationManager.AppSettings["appSecret"];
            string strOpenID = OAuthApi.GetAccessToken(strAppId, strAppSecret, strCode).openid;

            context.Response.ContentType = "text/plain";
            context.Response.Write(strOpenID);
            context.Response.End();

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}